1 package edu.jiangxin.apktoolbox.convert.protobuf.unsupervised; 2 3 import edu.jiangxin.apktoolbox.swing.extend.EasyPanel; 4 import edu.jiangxin.apktoolbox.utils.Constants; 5 import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; 6 import org.fife.ui.rsyntaxtextarea.SyntaxConstants; 7 import org.fife.ui.rtextarea.RTextScrollPane; 8 9 import javax.swing.*; 10 import java.awt.*; 11 12 public class ProtobufConvertPanel extends EasyPanel { 13 14 private JPanel contentPanel; 15 16 private JPanel operationPanel; 17 18 private JTextArea inputTextArea; 19 private RSyntaxTextArea outputTextArea; 20 21 @Override 22 public void initUI() { 23 BoxLayout boxLayout = new BoxLayout(this, BoxLayout.Y_AXIS); 24 setLayout(boxLayout); 25 26 createContentPanel(); 27 add(contentPanel); 28 add(Box.createVerticalStrut(Constants.DEFAULT_Y_BORDER)); 29 30 createOperationPanel(); 31 add(operationPanel); 32 } 33 34 private void createContentPanel() { 35 contentPanel = new JPanel(); 36 37 BoxLayout boxLayout = new BoxLayout(contentPanel, BoxLayout.X_AXIS); 38 contentPanel.setLayout(boxLayout); 39 40 inputTextArea = new JTextArea(); 41 inputTextArea.setLineWrap(true); 42 inputTextArea.setWrapStyleWord(true); 43 inputTextArea.setText("0a2f0a084a6f686e20446f6510011a106a6f686e406578616d706c652e636f6d220f0a0b3131312d3232322d33333310010a1e0a084a616e6520446f6510021a106a616e65406578616d706c652e636f6d"); 44 45 JScrollPane inputScrollPanel = new JScrollPane(inputTextArea); 46 inputScrollPanel.setPreferredSize(new Dimension(200, 500)); 47 48 outputTextArea = new RSyntaxTextArea(); 49 outputTextArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JSON); 50 outputTextArea.setCodeFoldingEnabled(true); 51 outputTextArea.setEditable(false); 52 53 RTextScrollPane outputScrollPane = new RTextScrollPane(outputTextArea); 54 outputScrollPane.setPreferredSize(new Dimension(200, 500)); 55 56 contentPanel.add(inputScrollPanel); 57 contentPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER)); 58 contentPanel.add(outputScrollPane); 59 } 60 61 private void createOperationPanel() { 62 operationPanel = new JPanel(); 63 64 BoxLayout boxLayout = new BoxLayout(operationPanel, BoxLayout.X_AXIS); 65 operationPanel.setLayout(boxLayout); 66 67 JButton convertButton = new JButton("Convert"); 68 69 convertButton.addActionListener(e -> convertProtoToJson()); 70 71 operationPanel.add(convertButton); 72 } 73 74 private void convertProtoToJson() { 75 String hexString = inputTextArea.getText(); 76 byte[] byteArray = ByteUtil.hex2bytes(hexString); 77 String jsonString = ProtobufDecoder.bytesDecoder(byteArray); 78 outputTextArea.setText(jsonString); 79 } 80 }